@extends('backend::modal')
@section('title',$page_title)
@push('styles')
    <link href="{{asset(config('view.plugin').'/layui/layui_ext/dtree/font/dtreefont.css')}}" rel="stylesheet">
    <link href="{{asset(config('view.plugin').'/layui/layui_ext/dtree/dtree.css')}}" rel="stylesheet">
@endpush
@section('content')
    <div class="row">
        <div class="col-lg-12">
            @component('backend::component.form.form')
                @slot('form_title') {{$page_title}} @endslot
                @slot('formId') auth-role @endslot
                @slot('action') {{route('b_Role_authRole',['role_id'=>$role->id])}} @endslot


                @component('backend::component.form.form-group')
                    @slot('title') 权限 @endslot
                    <div>
                        <ul id="actionsTree" data-content="{{$list}}" data-id="0"> </ul>
                    </div>
                    <input type="hidden" name="my_auth" value="{{$role->my_auth}}">
                @endcomponent

                @slot('buttons')
                    @component('backend::component.form.button')
                        @slot('title') 提交 @endslot
                        @slot('params') {"formId":"#auth-role"} @endslot
                        @slot('class') btn-min-width ajax-form @endslot
                    @endcomponent
                    @component('backend::component.form.button')
                        @slot('title') 重置 @endslot
                        @slot('type') reset @endslot
                        @slot('color') danger @endslot
                        @slot('class') btn-min-width @endslot
                    @endcomponent
                @endslot
            @endcomponent
        </div>
        <!--/.col-->
    </div>
@endsection
@push('scripts')
    <script>
        layui.use(['element','layer', 'dtree'], function(){
            var layer = layui.layer,
                dtree = layui.dtree,
                $ = layui.$;
            var data = $('#actionsTree').data('content');
            if(data.length>0){
                var defaultVal = "{{$role->my_auth}}".split(',');
                dtree.render({
                    elem: "#actionsTree",  //绑定元素
                    dot:false,
                    checkbar: true,
                    initLevel:'5',
                    defaultVal:defaultVal,
                    checkbarFun:{
                        chooseDone:function (params) {
                            var checkedIds = new Array();
                            for (var node in params) {
                                checkedIds.push(params[node].nodeId)
                            }
                            var checkedIdsStr = checkedIds.join(',')
                            $('input[name="my_auth"]').val(checkedIdsStr);
                        }
                    },
                    data:data
                });
            }
        });
    </script>
@endpush